/**
 * 游戏记录
 * @author sherwyn.Tang
 * @create 2015/03/07
 */
;(function (global){
	var CGI = {
			TEAM_REPORT: window.frontPath + 'team/pagingTeamReport?r=' + new Date().getTime(),//查询个人盈亏报表
			SUPER_PROXY :  window.frontPath + 'team/pagingSubTeamReport?r=' + new Date().getTime()//查询上级代理记录
	};
	//初始化输入框默认提示组件
	$.placeholder.init();
	
	 var startDateStr =DateUtil.dateToStr('yyyy-MM-dd');
	 jQuery("#startDate").val(startDateStr+" 00:00:00");
	/**
	 * 按条件查询
	 */
	$('#teamReport-search').click(function (){
		window.P(
			 1,
			 '#teamReport-search-form' , 
			  CGI.TEAM_REPORT , 
			 '#teamReport-z-template' , 
			 '#teamReport-data' , 
			 15,function (data){initSummary(data);}
		);
	});//.trigger('click');
	 
	
	$('#teamReport-data').delegate('[data-flag="data-super-proxy"]' , 'click' , function (){
		var _uid = $(this).parents('tr').attr('data-pid');
		window.P(
				 1,
				 '#teamReport-search-form' , 
				  CGI.SUPER_PROXY+'&uid='+_uid, 
				 '#teamReport-z-template' , 
				 '#teamReport-data' , 
				 15,function (data){initSummary(data);}
			);
	});
	
	$('#teamReport-data').delegate('[data-flag="data-sub-proxy"]' , 'click' , function (){
		var _uid = $(this).parents('tr').attr('data-uid');
		window.P(
				 1,
				 '#teamReport-search-form' , 
				 CGI.SUPER_PROXY+'&uid='+_uid, 
				 '#teamReport-z-template' , 
				 '#teamReport-data' , 
				 15,function (data){initSummary(data);}
			);
	});

})(window);



function initSummary(data)
{
 	//充值总额
 	var chargeAmountTotal = 0;
 	//提现金额
 	var cashAmountTotal = 0;
 	//投注金额
 	var betsAmountTotal = 0;
 	//中奖金额
 	var betsBonusTotal = 0;
 	//总返点
 	var fanDianAmountTotal = 0;
 	//佣金
 	var commissionTotal = 0;
 	
 	var awardTotal = 0;
 	//总盈亏
 	var totalYkTotal = 0;

 	var reportData = data.data.list;
 	for (var i = 0; i < reportData.length; i++) {
 		chargeAmountTotal += reportData[i]['chargeAmount'];
 		cashAmountTotal += reportData[i]['cashAmount'];
 		betsAmountTotal += reportData[i]['betsAmount'];
 		betsBonusTotal += reportData[i]['betsBonus'];
 		fanDianAmountTotal += reportData[i]['fanDianAmount'];
 		commissionTotal += reportData[i]['commission'];
 		awardTotal+= reportData[i]['award'];
 		//totalYkTotal += ( (+reportData[i]['betsBonus']) - (+reportData[i]['betsAmount']) - (+reportData[i]['commission']) );
 	};
 	totalYkTotal=betsBonusTotal+awardTotal+commissionTotal+fanDianAmountTotal-betsAmountTotal;
 	//本页总结
 	$('#teamReport-data').append($.substitute('<tr style="background-color:#DFFDFD;"><td colspan="3" style="text-align:right;">本页总结：</td><td>{chargeAmountTotal}</td><td>{cashAmountTotal}</td><td>{betsAmountTotal}</td><td>{betsBonusTotal}</td><td>{fanDianAmountTotal}</td><td>{commissionTotal}</td><td>{awardTotal}</td><td>{totalYkTotal}</td><td style="text-align:center">----</td></tr>',{
 		chargeAmountTotal : chargeAmountTotal.toFixed(4),
 		cashAmountTotal	  : cashAmountTotal.toFixed(4),
 		betsAmountTotal	  : betsAmountTotal.toFixed(4),
 		betsBonusTotal	  : betsBonusTotal.toFixed(4),
 		fanDianAmountTotal: fanDianAmountTotal.toFixed(4),
 		commissionTotal	  : commissionTotal.toFixed(4),
 		awardTotal:awardTotal.toFixed(4),
 		totalYkTotal	  : totalYkTotal.toFixed(4)
 	}));

 	
}